package top.zhangjianyong.tools.utils;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.time.LocalDateTime;
import java.util.*;

/**
 * @author ： zhangjianyong
 * @date ： 2023/7/20 01:31
 */
public class DaChenUtil {

    public static Map<String, Integer> ticketMap() {
        HttpRequest post = HttpUtil.createPost("http://dzsw.jjlypw.com/st9pc/shiplist/listbus");
        post.form("desName", "椒江 -- 下大陈");
        post.form("startTime", "2023-07-21");
        HttpResponse execute = post.execute();
        String body = execute.body();
        JSONObject json = JSONObject.parseObject(body);
        JSONArray jsonArray = json.getJSONObject("data").getJSONArray("shiplist");

        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject obj = jsonArray.getJSONObject(i);
            //String busTime = obj.getString("BusTime");//开船时间
            String busCode = obj.getString("BusCode");
            String vehicleName = obj.getString("VehicleName");//名字
            Integer netsellQuantity = obj.getInteger("NetsellQuantity");
          /*  String time = RegexUtil.matcherFirst(busTime, ".?Date\\(([0-9]{13})\\)", 1);
            LocalDateTime startTime = LocalDateTimeUtil.of(Long.valueOf(time));*/
            map.put(busCode+"-"+vehicleName, Integer.valueOf(netsellQuantity));
        }

        return map;
    }

    public static void main(String[] args) {
        Map<String, Integer> map = ticketMap();
        System.out.println(JSONObject.toJSONString(map));
    }
}
